<template>
  <div class="MineBag">
    <!-- 顶部用户信息 -->
    <div class="user-info">
      <img class="avatar" src="../../public/Me-headimg.png" alt="头像" />
      <div>
        <div class="nickname">{{ username || "未登录用户" }}</div>
        <div class="welcome">欢迎来到卡券包</div>
      </div>
    </div>

    <!-- Tab 切换 -->
    <div class="MineBag-title">
      <div
        :class="['MineBag-title-item', activeTab === 0 ? 'active' : '']"
        @click="activeTab = 0"
      >
        优惠券
      </div>
      <div
        :class="['MineBag-title-item', activeTab === 1 ? 'active' : '']"
        @click="activeTab = 1"
      >
        红包
      </div>
    </div>

    <!-- 卡券统计区 -->
    <div class="MineBag-stats">
      <div>
        <span>总数</span>
        <span class="num">{{ stats.total }}</span>
      </div>
      <div>
        <span>已用</span>
        <span class="num">{{ stats.used }}</span>
      </div>
      <div>
        <span>未用</span>
        <span class="num">{{ stats.unused }}</span>
      </div>
      <div>
        <span>已过期</span>
        <span class="num">{{ stats.expired }}</span>
      </div>
    </div>

    <!-- 卡券列表 -->
    <div class="MineBag-content">
      <div v-if="list.length" class="MineBag-list">
        <div v-for="item in list" :key="item.id" class="MineBag-card">
          <div class="card-left">
            <div class="card-title">{{ item.title }}</div>
            <div class="card-amount">￥{{ item.amount }}</div>
            <div class="card-date">有效期至：{{ item.expire }}</div>
          </div>
          <div class="card-right">
            <button v-if="item.status === 'unused'" class="use-btn">
              去使用
            </button>
            <span v-else-if="item.status === 'used'" class="used-btn"
              >已使用</span
            >
            <span v-else class="expired-btn">已过期</span>
          </div>
        </div>
      </div>
      <div v-else class="MineBag-empty">
        <img src="" alt="暂无卡券" />
        <div>暂无可用{{ activeTab === 0 ? "优惠券" : "红包" }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    // 示例数据
    return {
      username: "橙子用户",
      activeTab: 0,
      stats: {
        total: 3,
        used: 1,
        unused: 1,
        expired: 1,
      },
      couponList: [
        {
          id: 1,
          title: "满100减20",
          amount: 20,
          expire: "2025-12-31",
          status: "unused",
        },
        {
          id: 2,
          title: "满50减10",
          amount: 10,
          expire: "2025-06-30",
          status: "used",
        },
        {
          id: 3,
          title: "满200减50",
          amount: 50,
          expire: "2024-06-01",
          status: "expired",
        },
      ],
      redbagList: [
        {
          id: 4,
          title: "新人红包",
          amount: 8,
          expire: "2025-07-01",
          status: "unused",
        },
      ],
    };
  },
  computed: {
    list() {
      return this.activeTab === 0 ? this.couponList : this.redbagList;
    },
  },
};
</script>

<style scoped>
.MineBag {
  width: 100%;
  max-width: 480px;
  margin: 40px auto 0 auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(255, 80, 0, 0.08);
  padding-bottom: 32px;
  min-height: 220px;
}

/* 用户信息 */
.user-info {
  display: flex;
  align-items: center;
  padding: 24px 24px 0 24px;
  gap: 16px;
}
.avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #f3f3f3;
  object-fit: cover;
}
.nickname {
  font-size: 1.15em;
  font-weight: bold;
  color: #ff5000;
}
.welcome {
  font-size: 0.98em;
  color: #888;
  margin-top: 2px;
}

/* Tab */
.MineBag-title {
  display: flex;
  align-items: flex-end;
  width: 456px;
  height: 56px;
  border-bottom: 1.5px solid #f0f0f0;
  background: #f8fafc;
  border-radius: 16px 16px 0 0;
  padding-left: 24px;
  margin-top: 8px;
}
.MineBag-title-item {
  cursor: pointer;
  font-size: 18px;
  height: 38px;
  line-height: 38px;
  margin-right: 36px;
  padding: 0 18px;
  border-radius: 8px 8px 0 0;
  color: #555;
  position: relative;
  transition: color 0.2s, background 0.2s;
  font-weight: 500;
}
.MineBag-title-item.active {
  color: #ff5000;
  background: #fff;
  font-weight: 700;
}
.MineBag-title-item.active::after {
  content: "";
  display: block;
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 0;
  height: 3px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(90deg, #ffb86c 0%, #ff5000 100%);
}

/* 统计区 */
.MineBag-stats {
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin: 20px 0 0 0;
  padding: 0 12px;
}
.MineBag-stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #888;
  font-size: 0.98em;
}
.MineBag-stats .num {
  color: #ff5000;
  font-size: 1.2em;
  font-weight: bold;
  margin-top: 2px;
}

/* 卡券列表 */
.MineBag-content {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-top: 24px;
}
.MineBag-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 0 18px;
}
.MineBag-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, #fff7e6 0%, #ffe5d0 100%);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(255, 80, 0, 0.06);
  padding: 18px 22px;
  min-height: 68px;
}
.card-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-title {
  font-size: 1.08em;
  font-weight: 600;
  color: #222;
}
.card-amount {
  color: #ff5000;
  font-size: 1.3em;
  font-weight: bold;
}
.card-date {
  font-size: 0.95em;
  color: #888;
}
.card-right {
  display: flex;
  align-items: center;
  height: 100%;
}
.use-btn {
  background: linear-gradient(90deg, #ffb86c 0%, #ff5000 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 18px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.use-btn:hover {
  background: linear-gradient(90deg, #ff5000 0%, #ffb86c 100%);
}
.used-btn,
.expired-btn {
  color: #fff;
  background: #bbb;
  border-radius: 6px;
  padding: 6px 18px;
  font-size: 1em;
  font-weight: 600;
}
.expired-btn {
  background: #e0e0e0;
  color: #ff5000;
}

/* 空状态 */
.MineBag-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #bbb;
  font-size: 1.1em;
  margin-top: 32px;
}
.MineBag-empty img {
  width: 90px;
  margin-bottom: 16px;
  opacity: 0.7;
}

@media (max-width: 600px) {
  .MineBag {
    max-width: 98vw;
    padding-bottom: 18px;
  }
  .MineBag-title {
    padding-left: 8px;
    height: 48px;
  }
  .MineBag-title-item {
    font-size: 16px;
    margin-right: 16px;
    padding: 0 10px;
  }
  .MineBag-content {
    padding-top: 12px;
  }
  .MineBag-list {
    gap: 10px;
    padding: 0 2vw;
  }
  .MineBag-card {
    padding: 12px 8px;
    min-height: 54px;
  }
}
</style>